//
// Created by 86131 on 2023/11/29.
//
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<string> course[2501];
int main(){
    int m,n;
    scanf("%d %d",&m,&n);
    while(m--){
        char name[5];
        scanf("%s",name);
        int x;
        scanf("%d",&x);
        while(x--){
            int u;
            scanf("%d",&u);
            course[u].push_back(name);
        }
    }
    for(int i=1;i<=n;i++){
        sort(course[i].begin(),course[i].end());
        printf("%d %d\n",i,course[i].size());
        for(int j=0;j<course[i].size();j++){
            printf("%s\n",course[i][j].c_str());
        }
    }

}